package handler

import (
	"net/http"
	v1 "server_go/api/v1"
	"server_go/internal/service"

	"github.com/gin-gonic/gin"
)

type AdminHandler struct {
	*Handler
	adminService service.AdminService
}

func NewAdminHandler(handler *Handler, adminService service.AdminService) *AdminHandler {
	return &AdminHandler{
		Handler:      handler,
		adminService: adminService,
	}
}

func (h *AdminHandler) Login(ctx *gin.Context) {
	req := new(v1.LoginAdminRequest)
	if err := ctx.ShouldBind(req); err != nil {
		v1.HandleError(ctx, http.StatusBadRequest, err, nil)
		return
	}

	token, err := h.adminService.Login(ctx, req)
	if err != nil {
		v1.HandleError(ctx, http.StatusInternalServerError, err, nil)
		return
	}

	v1.HandleSuccess(ctx, v1.LoginAdminResponse{
		AccessToken: token,
	})
}
